﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Common;

namespace AI.Steering
{
	/// <summary>
    /// 雷达：扫描相邻物体
    /// </summary>
	public class Radar : MonoBehaviour {
        //相邻物体标签
        [Tooltip("相邻物体标签")]
        public string targetTag;
        [Tooltip("扫描半径")]
        public float scanDistance = 8;
        [Tooltip("扫描间隔")]
        public float scanInterval = 0.5f;
        //[HideInInspector]
        public List<Transform> targetList;
        private void Awake()
        {
            targetList = new List<Transform>();
        }
        private void OnEnable()
        {
            StartCoroutine("ScanTargets");//用字符串开启协程用的是反射，不建议使用，性能不好
        }
        private void OnDisable()
        {
            StopCoroutine("ScanTargets");
        }
        //扫描同伴
        private IEnumerator ScanTargets()
        {
            while (true)
            {
                targetList.Clear();
                targetList.AddRange(TransformHelper.CalculateAroundObject(transform, scanDistance, 360, new string[] { targetTag }));
                yield return new WaitForSeconds(scanInterval);
            }
        }
	}
}

